import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os

def plot_daily(values, f_or_title='daily curve', hr_per_pt=0.5, mode='show', root_out=None):
    ulim = int(24 / hr_per_pt)
    data = values[:ulim]
    tlist = np.linspace(hr_per_pt, 24+hr_per_pt, ulim)
    fig = plt.figure()
    plt.title(f_or_title)
    plt.plot(tlist, data)
    plt.xlabel('ZT hour')
    plt.xlim([-1, 25])
    plt.ylim([0, 1850])
    if mode == 'show':
        plt.show()
    else:
        if root_out is None:
            plt.savefig(f_or_title+'.png')
        else:
            plt.savefig(os.path.join(root_out, f_or_title+'.png'))
    plt.close(fig)